if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.user.ResetPsw")) {
	jsx3.require("jsx3.gui.Dialog")
/**
*
*/
jsx3.lang.Package.definePackage("tibco.admin.enterpriseAssets.userMgt.user", function (resetPsw) {
});

/**
*
*/
jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.userMgt.user.ResetPsw",
        jsx3.gui.Dialog,
        null,
        function (resetPsw) {

			/**
			 * instance initializer
			 */
			resetPsw.prototype.initialize = function() {
				this.saveBtn = this.getDescendantOfName("btnSave_24_D_3");
				this.psw = this.getDescendantOfName("txtPsw_24_D_3");
				this.pswConfirm = this.getDescendantOfName("txtPswCfm_24_D_3");
				this.userid = this.getDescendantOfName("lblUserIdValue_24_D_3");

				var me = this;
				this.saveBtn.doSave = function(){
					var errorCode = me.confirmPsw();
					if(errorCode==0){
						me.doSave();
					}
					else{
						me.getDescendantOfName("lblTip_24_D_3").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
						if(errorCode==1)
							me.getDescendantOfName("lblTip_24_D_3").
								setText(tibco.admin.Main.getServer().getDynamicProperty("@@inputValidPassword"), true);
						else
							if(errorCode==2)
								me.getDescendantOfName("lblTip_24_D_3").
									setText(tibco.admin.Main.getServer().getDynamicProperty("@@passwordNotMatch"), true);
					}
				}

					this.passedItems["pwd"] = false;//070818
					this.passedItems["confirmPwd"] = false;//070818
			}

			/**
			 * Check whether the password and confirm password are the same
			 *    ERROR_CODE   0: valid
			 *                        1: password length &lt; 0
			 *	 					   2: password and confirm password not match
			 */
			resetPsw.prototype.confirmPsw = function(){
				if(this.psw.getValue().length<0){
					return 1;
				}else{
						if(this.psw.getValue() == this.pswConfirm.getValue()){
							return 0;
						}
						else{
							return 2;
						}
				}
			}

			/**
			 *	Reset the password
			 */
			resetPsw.prototype.doSave = function(){
				this.callresetPassword();
			}


			//========== call web service ===============
			/**
			 *	  Reset the password of the selected user - webservice call
			 */
			resetPsw.prototype.callresetPassword = function() {
			  var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/user/rules/resetPassword.xml", "resetPassword", "Reset Password");
			  //subscribe and call
			  objService.subscribe(jsx3.net.Service.ON_SUCCESS, this,this.onresetPasswordSuccess);
			  //objService.subscribe(jsx3.net.Service.ON_ERROR, this,this.onresetPasswordError);
			  //objService.subscribe(jsx3.net.Service.ON_INVALID, this,this.onresetPasswordInvalid);
			  objService.username=this.userid.getText();
			  objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
			  objService.doCall();
			};

			resetPsw.prototype.onresetPasswordSuccess = function(objEvent) {
              tibco.admin.util.Log.USERMGT.trace("Success, Password for user "+objEvent.target.username+" is reset.");
			  this.doClose();
			};

			resetPsw.prototype.onresetPasswordError = function(objEvent) {
			  var myStatus = objEvent.target.getRequest().getStatus();
			  tibco.admin.util.Log.USERMGT.error("Error","The service call failed. The HTTP Status code is: " + myStatus);
			};

			resetPsw.prototype.onresetPasswordInvalid = function(objEvent) {
			  tibco.admin.util.Log.USERMGT.error("Invalid","The following message node just failed validation:\n\n" + objEvent.message);
			};
			//===============================================


				/*070818
				* if user doesn't fishish all the required fields, the "save" button will be disabled.
				*/
				resetPsw.prototype.passedItems = {};

                resetPsw.prototype.valiPwd = function(obj, strValue) {
                    this.passedItems["pwd"] = tibco.admin.util.Validation.doValidateNotEmptyNoWhSpace(obj, strValue, tibco.admin.Main.getServer().getDynamicProperty("@@lblPassword_24_C"));
					this.enableSaveBtn4Add();
                };

                resetPsw.prototype.valiConfirmPwd = function(obj, strValue) {
                    this.passedItems["confirmPwd"] = tibco.admin.util.Validation.doValidateNotEmptyNoWhSpace(obj, strValue, tibco.admin.Main.getServer().getDynamicProperty("@@lblCfmPassword_24_C"));
					this.enableSaveBtn4Add();
                };

                resetPsw.prototype.enableSaveBtn4Add = function() {
					var allPassed = true;
					allPassed = this.PwdMatch();
					for (var item in this.passedItems) {
						if(!this.passedItems[item]) allPassed = false;
					}
					if(allPassed) this.getDescendantOfName("btnSave_24_D_3").setEnabled(jsx3.gui.Form.STATEENABLED, true);
					else this.getDescendantOfName("btnSave_24_D_3").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
				}
				resetPsw.prototype.PwdMatch = function() {
					var flag = true;
					if(this.passedItems["pwd"] && this.passedItems["confirmPwd"]) {
						if(this.getDescendantOfName("txtPsw_24_D_3").getValue() != this.getDescendantOfName("txtPswCfm_24_D_3").getValue()){
							var notMatchTxt = tibco.admin.Main.getServer().getDynamicProperty("@@passwordNotMatch");
//							tibco.admin.Main.alert(notMatchTxt, notMatchTxt);
							flag = false;
						}
					}
					return flag;
				}


        });
    }